package cn.wizzer.app.web.commons.ext.websocket.monitor;

import cn.wizzer.app.web.commons.ext.websocket.main.base.NettyCache;
import cn.wizzer.app.web.commons.ext.websocket.main.monitor.BaseNettyMonitor;
import cn.wizzer.app.web.commons.ext.websocket.main.monitor.NettyMonitor;
import io.netty.channel.ChannelHandlerContext;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;

@IocBean
//在默认清理前清理此处数据
@NettyMonitor(order = -1)
public class ChatNettyMonitor extends BaseNettyMonitor {

    @Override
    public void added(ChannelHandlerContext ctx) {

    }

    @Override
    public void removed(ChannelHandlerContext ctx) {
        //清理当前用户对应全局缓存
        String currentUserId = NettyCache.localGet(ctx.channel(),"currentUserId");
        if (Strings.isNotBlank(currentUserId)) {
            NettyCache.globalRemove(currentUserId);
        }
    }
}
